﻿using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using Less.SRV;
using Less.Core;
using Less.Core.Model;

namespace Less.REST
{
    [ServiceContract(Name = "Config")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true)]
    public class ConfigREST : ConfigSRV
    {
        public ConfigREST()
            : base("lessConnection")
        {
        }

        public ConfigREST(string connectionStringName) : base(connectionStringName)
        {
        }

        [WebGet(UriTemplate = "", ResponseFormat = WebMessageFormat.Json)]
        public new List<ConfigSetting> GetAll()
        {
            return Web.Templates.FunctionTemplate(base.GetAll, EntryCategories.REST);
        }

        [WebGet(UriTemplate = "{id}", ResponseFormat = WebMessageFormat.Json)]
        public new ConfigSetting Get(string id)
        {
            return new ConfigSetting() { Id = int.Parse(id) };
            //return Web.Templates.FunctionTemplate(base.Get, id);
        }

        [WebGet(UriTemplate = "?code={code}", ResponseFormat = WebMessageFormat.Json)]
        public new ConfigSetting GetByCode(string code)
        {
            return Web.Templates.FunctionTemplate(base.GetByCode, code);
        }

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public new ConfigSetting Create(ConfigSetting instance)
        {
            return Web.Templates.FunctionTemplate(base.Create, instance);
        }

        [WebInvoke(UriTemplate = "", Method = "PUT")]
        public new ConfigSetting Update(ConfigSetting instance)
        {
            return new ConfigSetting() { Id = instance.Id };
            //return Web.Templates.FunctionTemplate(base.Update, instance);
        }

        [WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
        public new void Delete(string id)
        {
            //Web.Templates.ActionTemplate(base.Delete, id, EntryCategories.REST);
        }
    }
}